package com.koo.modules.comm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.comm.dao.CommUploadRecordDao;
import com.koo.modules.comm.entity.CommUploadRecordEntity;
import com.koo.modules.comm.service.CommUploadRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class CommUploadRecordServiceImpl extends ServiceImpl<CommUploadRecordDao, CommUploadRecordEntity> implements CommUploadRecordService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<CommUploadRecordEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), CommUploadRecordEntity::getTableName, key)
                .or().like(MyStrUtil.isNotEmpty(key), CommUploadRecordEntity::getDownloadDate, key);

        IPage<CommUploadRecordEntity> page = this.page(
                new Query<CommUploadRecordEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<CommUploadRecordEntity> listByTableName(Long storeId, String tableName) {
        LambdaQueryWrapper<CommUploadRecordEntity>  wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CommUploadRecordEntity::getStoreId, storeId);
        wrapper.eq(CommUploadRecordEntity::getTableName, tableName);
        wrapper.isNotNull(CommUploadRecordEntity::getRemark);
        return baseMapper.selectList(wrapper);
    }

}